package com.weiiew.backend.operation;

import com.weiiew.backend.operationUtils.KeyCode;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.awt.*;

/**
 * @Description
 * @Author 魏锴
 * @Date 2025/4/26
 */
@Setter
@Getter
@ToString
@AllArgsConstructor
public class KeyPress extends ComputerOperation {
    private static final long serialVersionUID = 121204894512L; // 添加 serialVersionUID
    private final KeyCode keyCode;

    public KeyPress(long timestamp, String desc) {
        this.setTimestamp(timestamp);
        this.keyCode = KeyCode.valueOf(desc);
    }

    public KeyPress(KeyCode keyCode, long timestamp) {
        super.setTimestamp(timestamp);
        this.keyCode = keyCode;
    }

    @Override
    public String toDescriptionString() {
        return String.format("kp@%d@%s",
                this.getTimestamp(), keyCode.name());
    }

    @Override
    public void execute(Robot robot) {
        robot.keyPress(keyCode.getRobotCode());
    }
}
